import moment from "moment";
// 全局千分位
export const thousands = (num, len) => {
  try {
    if (len) {
      return `${(num * 1).toFixed(len)}`.replace(
        /\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,
        "$&,"
      );
    } else {
      return `${(num * 1).toFixed(2)}`.replace(
        /\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,
        "$&,"
      );
    }
  } catch (error) {
    return num;
  }
};

export const dateYMDHMSFormat = (dateStr, pattern = "YYYY-MM-DD HH:mm:ss") => {
  if (!dateStr) return;
  return moment(dateStr).format(pattern);
};

export const dateYMDFormat = (dateStr, pattern = "YYYY-MM-DD") => {
  if (!dateStr) return;
  return moment(dateStr).format(pattern);
};
